<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/7/1 15:00
 * Modified Time: 2019/7/1 15:00
 * Version: 2.0
 */

namespace App\Modules\MemberCard\Criterias;


use Flower\Core\Repository\Contracts\CriteriaInterface;
use Flower\Core\Repository\Contracts\RepositoryInterface;

class GetCardTypeByIdCriteria  implements CriteriaInterface
{
    private $card_type_id;

    public function __construct($card_type_id)
    {
        $this->card_type_id = $card_type_id;
    }

    public function apply($model, RepositoryInterface $repository)
    {
        $card_type_id = $this->card_type_id;


        //查询
        $select = '
            hx_card_type.id,
            hx_card_type.store_id,
            hx_card_type.name,
            category,
            price,
            if(category=1,count,present + price) as amount,
            hx_store.name as store_name
            
        ';

        $model = $model->selectRaw($select)->where('card_type.id',$card_type_id)
                        ->leftJoin('store','store_id','store.id');

        return $model;
    }
}